import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName LC73
 * @Author ykx
 * @Date 2024/3/28 13:56
 * @Version 1.0
 */
public class LC73 {
    public static void main(String[] args) {
        LC73 lc73 = new LC73();
        int[][] matrix;
        matrix = new int[][]{{0, 1, 2, 0}, {3, 4, 5, 2}, {1, 3, 1, 5}};
        lc73.setZeroes(matrix);
        System.out.println(Arrays.deepToString(matrix));
    }

    public void setZeroes(int[][] matrix) {
        List<int[]> positions = new ArrayList<>();
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] == 0) {
                    positions.add(new int[]{i, j});
                }
            }
        }
        for (int i = 0; i < positions.size(); i++) {
            setZero(matrix, positions.get(i)[0], positions.get(i)[1]);
        }
    }

    public void setZero(int[][] matrix, int row, int col) {
        // 设置第row行为0
        for (int i = 0; i < matrix[row].length; i++) {
            matrix[row][i] = 0;
        }

        // 设置第col列为0
        for (int i = 0; i < matrix.length; i++) {
            matrix[i][col] = 0;
        }
    }

}

